package com.loong.seller.controller.backend;

import com.loong.common.domain.BaseQuery;
import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.common.validator.group.CommonValidate;
import com.loong.seller.common.backend.param.ShopContactParam;
import com.loong.seller.common.backend.param.ShopContactQueryParam;
import com.loong.seller.handler.ShopContactHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description: 店铺联系控制器
 * @Author: hzp
 * @Date: 2020-10-26 13:39
 */
@RestController
@RequestMapping("/manage/seller/shopContact")
public class ShopContactController extends BaseBackendController {
    @Resource
    private ShopContactHandler shopContactHandler;


    /**
     * 保存店铺联系信息
     * @param param 店铺联系信息
     * @return 200
     */
    @PostMapping("save")
    public Result save(@Validated(value = {CommonInsert.class, CommonValidate.class}) ShopContactParam param){
        param.setId(null);
        return   handlerExecutor.execute(()->shopContactHandler.save(param));
    }

    /**
     * 更新店铺联系信息
     * @param param 店铺联系信息
     * @return 200
     */
    @PostMapping("update")
    public Result update(@Validated(value = {CommonUpdate.class, CommonValidate.class}) ShopContactParam param){
        return  handlerExecutor.execute(()->shopContactHandler.update(param));
    }

    /**
     *根据id删除店铺联系信息
     * @param id 店铺联系 id
     */
    @PostMapping("delete")
    public Result deleteById(@RequestParam("id") Long id){
        return handlerExecutor.execute(()->shopContactHandler.deleteById(id));
    }

    /**
     * 根据店铺id查找联系方式
     * @param shopId 店铺id
     * @return
     */
    @PostMapping("findContactByShopId")
    public Result findContactByShopId(Long shopId){
        return handlerExecutor.execute(()->shopContactHandler.findContactByShopId(shopId));
    }

    /**
     * 分页查询
     * @param baseQuery 分页对象
     * @param param 查询条件
     * @return
     */
    @PostMapping("pageQuery")
    public Result pageQuery(BaseQuery baseQuery, ShopContactQueryParam param){
        return  handlerExecutor.execute(()->shopContactHandler.pageQuery(baseQuery,param));
    }
}
